package com.jxd.hbase.analysis;

import com.jxd.config.HbaseConfig;
import com.jxd.entity.MesHead;
import com.jxd.model.SwitchCover;
import com.jxd.service.impl.SwitchCoverServiceImpl;
import org.apache.hadoop.hbase.client.Connection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SwitchCovers {
    @Autowired
    SwitchCoverServiceImpl switchCoverService;
    @Autowired
    private HbaseConfig hbaseConfig;
    @Value("${hbase.bwcontent.tablename}")
    private String bwContentTableName;

    public void qurryCommMessSwitchCover(String fileName, String shipid, String mesId ,String xtid,Connection connection) {
        long st = new Date().getTime();
        String tableName = bwContentTableName;
        System.out.println(tableName);
        System.out.println(connection);
        //获取所有的控制报文
        List<MesHead> comMesHeadList =
                switchCoverService.getCommMess(fileName, mesId, shipid);
        long end = new Date().getTime();
        System.out.println(end-st);
        //获取所有的61632维护报文
        end = new Date().getTime();
        System.out.println(end-st);
        //获取控制报文下的开关盖数组
        List<SwitchCover> comMesSwitchCovers =
                switchCoverService.qurryCommMessSwitchCover(comMesHeadList, connection,tableName);
        end = new Date().getTime();
        //写入oracle
        switchCoverService.insertSwitchCover(comMesSwitchCovers, xtid,shipid);
        end = new Date().getTime();
        System.out.println(end-st);
    }


    ///
    public void qurryMaintainSwitchCoverss(String fileName, String shipid, String mesId ,String xtid,Connection connection){
        long st = new Date().getTime();
        String tableName = bwContentTableName;
        System.out.println(tableName);
        System.out.println(connection);
        //获取所有的控制报文
        List<MesHead> comMesHeadList =
                switchCoverService.getCommMess(fileName, mesId, shipid);
        long end = new Date().getTime();
        System.out.println("es用时"+(end-st));
        //获取控制报文下的开关盖数组
        List<SwitchCover> maintainSwitchCoverss =
                switchCoverService.qurryMaintainSwitchCoverss(comMesHeadList, connection,tableName);
        end = new Date().getTime();
        //写入oracle
        switchCoverService.insertSwitchCover(maintainSwitchCoverss, xtid,shipid);
        end = new Date().getTime();
        System.out.println("总用时"+(end-st));
    }

}
